<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<div th:replace="common/common::html"></div>
<head>
    <meta charset="UTF-8">
    <title th:text="#{recycle.title}">Title</title>
    <script th:inline="javascript">
        var _gridWidth = null;
        var _gridHeight = null;
        //页面自适应
        function resizePageSize(){
            _gridWidth = $(window).width()-12;/*  -189 是去掉左侧 菜单的宽度，   -12 是防止浏览器缩小页面 出现滚动条 恢复页面时  折行的问题 */
            _gridHeight = $(window).height()-32-75; /* -32 顶部主菜单高度，   -140 查询条件高度*/
        }
        $(function () {
            window.addEventListener("resize",function () {
                resizePageSize();
                $("#flexgrid-id").flexResize(_gridWidth,_gridHeight);
            })
            resizePageSize();
            var _columnWidth = (_gridWidth - 150)/6;
            //表格
            $("#flexgrid-id").flexigrid({
                width : _gridWidth,
                height : _gridHeight,
                url : /*[[@{queryFileListByPage}]]*/"",
                dataType : 'json',
                colModel : [
                    {display : 'fileUuid',name : 'fileUuid',sortable : false,align : 'center',hide : 'true'},
                    {display : /*[[#{file.name}]]*/"",name : 'fileName',width : _columnWidth, sortable : true,align : 'center'},
                    {display :  /*[[#{file.capacity}]]*/"",name : 'fileCapacity',width : _columnWidth, sortable : true,align : 'center'},
                    {display :  /*[[#{file.path}]]*/"",name : 'filePath',width : _columnWidth, sortable : true,align : 'center'},
                    {display :  /*[[#{user.uuid}]]*/"",name : 'userUuid',width : _columnWidth, sortable : true,align : 'center'},
                    {display :  /*[[#{file.modtime}]]*/"",name : 'modtime',width : _columnWidth, sortable : true,align : 'center'},
                    {display :  /*[[#{common.operation}]]*/"",name : 'fileUuid',width : _columnWidth, sortable : true,align : 'center',
                        process: function(v,_trid,_row){

                            var contents = "";
                            //恢复
                            if([[${#authorization.expression("hasRole('ROLE_cldk_data_offer')")}]]) {
                                contents += '<a class="btn" title=[[#{file.restore}]] onclick="restoreFile(\'' + v + '\')"><i class="glyphicon glyphicon-repeat"></i></a>';

                            }
                            //删除
                            if([[${#authorization.expression("hasRole('ROLE_cldk_file_del')")}]]) {
                                contents += '<a class="btn"title=[[#{file.delete}]] onclick="deleteFile(\'' + v + '\',\'' + _row.fileName + '\')"><i class="glyphicon glyphicon-trash"></i></a>';
                            }
                            return contents;
                        }},
                ],
                resizable : false, //resizable table是否可伸缩
                useRp : true,
                usepager : true, //是否分页
                autoload : false, //自动加载，即第一次发起ajax请求
                hideOnSubmit : true, //是否在回调时显示遮盖
                showcheckbox : true, //是否显示多选框
                //rowhandler : rowDbclick, //是否启用行的扩展事情功能,在生成行时绑定事件，如双击，右键等
                rowbinddata : true
            });
            //搜索框
            $("#nav-tools-article-id").searchTools({
                colModel : [
                    {display : /*[[#{file.name}]]*/"", domId:"search-file-name"},
                ],
                reback:function () {
                    query();
                }
            });
            query();
            //查询按钮
            $("#query-btn-id").click(function () {
                query();
            });
            //删除文件对话框
            $("#allow-delete-dialog-id").dialog({
                autoOpen : false,
                width : 400,
                modal : true,
                resizable : false,
                title: /*[[#{file.conform.delete.dialog}]]*/'',
                buttons: [
                    {
                        text: /*[[#{common.confirm}]]*/'',
                        click: function() {
                            var fileUuid= $("#allow-delete-dialog-id").attr("fileUuid");
                            $.ajax({
                                type: 'post',
                                async: false,
                                dataType : 'json',
                                url: /*[[@{deleteFile}]]*/'',
                                data: [
                                    {name:"fileUuid",value:fileUuid}
                                ],
                                success: function (data) {
                                    message(data.msg);
                                    $("#allow-delete-dialog-id").dialog('close');
                                },
                                error: function(msg){
                                    message(/*[[#{common.error}]]*/'');
                                }
                            });
                        }
                    },
                    {
                        text: /*[[#{common.cancel}]]*/'',
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    },
                ]
            });
            //恢复文件对话框
            $("#allow-restore-dialog-id").dialog({
                autoOpen : false,
                width : 400,
                modal : true,
                resizable : false,
                title: /*[[#{file.conform.restore.dialog}]]*/'',
                buttons: [
                    {
                        text: /*[[#{common.confirm}]]*/'',
                        click: function() {
                            var fileUuid= $("#allow-restore-dialog-id").attr("fileUuid");
                            $.ajax({
                                type: 'post',
                                async: false,
                                dataType : 'json',
                                url: /*[[@{restoreFile}]]*/'',
                                data: [
                                    {name:"fileUuid",value:fileUuid}
                                ],
                                success: function (data) {
                                    message(data.msg);
                                    $("#allow-restore-dialog-id").dialog('close');
                                },
                                error: function(msg){
                                    message(/*[[#{common.error}]]*/'');
                                }
                            });
                        }
                    },
                    {
                        text: /*[[#{common.cancel}]]*/'',
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    },
                ]
            });


        });//ready function
        function query() {
            var  fileName = $("#search-file-name").attr("select-value");
            $("#flexgrid-id").flexOptions({
                extParam:[
                    {name:"fileName",value:fileName}
                ]
            }).flexReload();
        }
        //删除文件
        function deleteFile(fileUuid,fileName) {
            $("#mo-file-name-id").val(fileName);
            $("#allow-delete-dialog-id").attr("fileUuid",fileUuid);
            $("#allow-delete-dialog-id").dialog('open');
        }
        //恢复文件
        function restoreFile(fileUuid) {
            $("#allow-restore-dialog-id").attr("fileUuid",fileUuid);
            //message("删除成功!");
            $("#flexgrid-id").flexReload();
            $("#allow-restore-dialog-id").dialog('open');
        }



    </script>
</head>
<body style="display: flex;flex-direction: column">
<nav style="flex-basis: 31px;display: flex;flex-direction: row;margin:5px 0">
    <!--        <input id="dir-id">-->
    <article id="nav-tools-article-id" class="nav-tools-article"></article>
    <nav style="flex-grow: 1">
        <a id="query-btn-id" class="btn" th:title="#{common.query}">
            <i class="glyphicon glyphicon-search"></i>
        </a>

    </nav>
</nav>
<table id="flexgrid-id" style="flex-grow: 1"></table>

<div id="allow-auth-dialog-id"style="display: none">
    <ul id="allow-auth-ztree-id" class="ztree"></ul>
</div>
<div id="allow-delete-dialog-id">
    <span th:text="#{file.name}"></span>
    <input id="mo-file-name-id" class="form-control" name="fileName">
</div>
<div id="allow-restore-dialog-id"></div>
</body>
</html>